package com.power.leopard.remote.http;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

import com.power.leopard.remote.Server;
import com.power.leopard.remote.common.codec.SerializerFactory;

public class HttpServerHandler implements HttpHandler {

	private Server server;

	public HttpServerHandler(Server server) {
		this.server = server;
	}

	public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String uri = request.getRequestURI();
		String path = uri.substring(uri.lastIndexOf("/") + 1);

		String serialize = request.getParameter("serialize");
		if (serialize == null) {
			serialize = request.getHeader("serialize");
		}

		if (StringUtils.isEmpty(serialize)) {
			response.setStatus(200);
			return;
		}

		String method = request.getMethod();
		byte parseByte = Byte.parseByte(serialize);
		if (!method.equalsIgnoreCase("POST")) {
			if (SerializerFactory.SERIALIZE_JSON == parseByte) {
				response.setStatus(200);
			} else {
				response.setStatus(500);
			}
		} else {

		}
	}

}
